package cn.wolfcode.crm.query;

import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter
@Setter
public class SaleChartQueryObject extends QueryObject {

	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date beginDate;
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date endDate;
	private long clientId = -1L;
	private long agencyId = -1L;
	private long productId = -1L;
	private String groupByType;//分组的类型
	//使用map结合封装分组的类型
	//分组类型只需要初始化一次就行了 //GROUP BY saleman.name/p.name/c.name/p.brand_name/sa.vdate
	public static Map<String,String>  groupByTypes = new LinkedHashMap<>();
	static {
		groupByTypes.put("saleman.username","销售人员");
		groupByTypes.put("ai.name","保险机构");
		groupByTypes.put("p.name","商品名称");
		groupByTypes.put("c.clientName","客户");
		groupByTypes.put("DATE_FORMAT(sto.purchasedate,'%Y-%m')","保单日期(月)");
		groupByTypes.put("DATE_FORMAT(sto.purchasedate,'%Y-%m-%d')","保单日期(日)");
	}

	public String getGroupByType(){
		if(groupByType==null || groupByType.trim().length()==0){
			return "saleman.username";
		}
		return groupByType;
	}
}
